<script setup lang="ts">
import { ref } from 'vue';
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';

defineOptions({
  name: 'GameRecordDetailSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();


const model = defineModel<Api.Games.GameRecordDetailSearchParams>('model', { required: true });


async function reset() {
  Object.assign(model.value.params!, {});
  await restoreValidation();
  emit('reset');
}

async function search() {
  await validate();
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="user-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi span="24 s:12 m:6" label="游戏记录ID" path="recordId" class="pr-24px">
              <NInput v-model:value="model.recordId" placeholder="请输入游戏记录ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="用户ID" path="userId" class="pr-24px">
              <NInput v-model:value="model.userId" placeholder="请输入用户ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="游戏编码" path="gameCode" class="pr-24px">
              <NInput v-model:value="model.gameCode" placeholder="请输入游戏编码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="Emoji的Unicode编码" path="emojiUnicode" class="pr-24px">
              <NInput v-model:value="model.emojiUnicode" placeholder="请输入Emoji的Unicode编码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="Emoji字符" path="emojiChar" class="pr-24px">
              <NInput v-model:value="model.emojiChar" placeholder="请输入Emoji字符" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="本局消灭数量" path="eliminatedCount" class="pr-24px">
              <NInput v-model:value="model.eliminatedCount" placeholder="请输入本局消灭数量" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="消灭时间" path="eliminatedTime" class="pr-24px">
              <NDatePicker
                v-model:formatted-value="model.eliminatedTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                clearable
              />
            </NFormItemGi>
            <NFormItemGi span="24" class="pr-24px">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
